<template>
	<view class="login">
		<view class="imageBox">
			<image :src="'/static/login/bg.png'" mode="widthFix"></image>
		</view>
		<view class="btnBox">
			<view class="tex">
				<text>欢迎登录 ！</text>
			</view>
			<view class="choose-nickname-row">
				<input v-model="username" @blur="inputName" type="nickname" placeholder="请输入账号"
					style="color: #807E7E;" class='codeinput' />
			</view>
			<view class="choose-nickname-row">
				<input v-model="password" @blur="inputPassword" type="nickname" placeholder="请输入密码" password
					style="color: #807E7E;" class='codeinput' />
			</view>
		</view>
		<button class="btn" @tap.stop="btnlogin" v-if="hideshow">登录</button>
		<wxLoginPopup v-show="showPop" :showPop="showPop" @update="close" :optins="t" :mobile="mobile" @changeMobile="changeMobile" />
	</view>
</template>

<script>
	import wxLoginPopup from './login-popup.vue';

	export default {
		data() {
			return {
				image: this.$base.smallimgUrl,
				checked: true,
				showPop: false,
				mobile: '',
				t:null,
				username:'',
				password:'',
				docmHeight: document.documentElement.clientHeight,  //默认屏幕高度
				showHeight: document.documentElement.clientHeight,   //实时屏幕高度
				hideshow:true,
			};
		},
		mounted() {
		  // window.onresize监听页面高度的变化
		  window.onresize = ()=>{
		    return(()=>{
		      this.showHeight = document.body.clientHeight;
		    })()
		  }
		},
		watch:{
		  showHeight:function() {
		    if(this.docmHeight > this.showHeight){
				console.log('我被顶出去了')
		      this.hideshow = false
		    }else{
		      this.hideshow=true
			  	console.log('我没又')
		    }
		  }
		},
		components: {
			wxLoginPopup
		},
		onLoad(options) {
			this.t = options
			console.log(this.t,'sss')
			this.$utils.toast(options)
			
		},
		
		methods: {
			exitLogin(){
				uni.switchTab({
					url: '/pages/tabBar/home/home'
				})
			},
			Jump(type){
				uni.navigateTo({
					url: '/pages/my/agreement/agreement?type=' + type
				})
			},
			changeMobile(){
				this.mobile = uni.getStorageSync('mobile')
			},
			// 点击登录
			loginBtn(e){
				let that = this
				// if(!that.checked) return that.$utils.toast('请阅读勾选用户协议与隐私协议')
				// that.$api.getWxPhone({
				// 	code: e.detail.code
				// }).then(res => {
				// 	if (res.data.code == 1) {
				// 		this.mobile = res.data.data.mobile
				// 		uni.setStorageSync('mobile', this.mobile)
				// 		this.showPop = true
				// 	}
				// })
				this.showPop = true
			},
			btnlogin(){
				if (this.username == '') {
					uni.showToast({
						title: '请输入账号',
						icon: 'none'
					});
					return false;
				}
				if (this.password == '') {
					uni.showToast({
						title: '密码不能为空',
						icon: 'none'
					});
					return false;
				}
				let that = this
				const paramsData = {
					username: that.username,
					password: that.password,
					type: 'substation_user'
				}
				// if(uni.getStorageSync('scene')) paramsData.shareBy = uni.getStorageSync('scene')

				that.$api.wxLogin(paramsData).then(r => {
					uni.showToast({
						title: '登录成功',
						duration: 1500
					})
					console.log(r,'rrrrrrrrrrrr')
					uni.removeStorageSync('scene')
					that.close()
					// this.getSearchList()
					uni.setStorageSync('userInfo', r.data)
					// this.show = false;
					uni.setStorageSync('token', r.data.token)
					// this.$emit('update')
					// uni.$emit('hasLogin', true)

					console.log('我进来了')
					setTimeout(() => {
						uni.switchTab({
							url: '/pages/tabBar/home/home'
						})
					},2000)
				})
			},
			inputName(e){
				const {
					value
				} = e.detail
				this.username = value
			},
			inputPassword(e){
				const {
					value
				} = e.detail
				this.password = value
			},
			close() {
				this.showPop = false
			},
		
		}
	}
</script>

<style lang="less">
	.btn {
		position: absolute;
		left: 5%;
		top: 56%;
		width: 90%;
		height: 96rpx;
		background: #469D96;
		color: #fff;
		border-radius: 20rpx;
		text-align: center;
		line-height: 96rpx;
		font-size: 28rpx;
		font-weight: 500;
		margin: 30rpx auto;
		margin-top: 70rpx;
	}
	.login {
		width: 100vw;
		height: 100vh;
		position: relative;

		.imageBox {
			width:600rpx;
			position: absolute;
			left: 11%;
			top: 100rpx;
			image {
				width: 100%;
			}

		}

		.btnBox {
			width: 100%;
			height: 400rpx;
			background: #fff;
			position: absolute;
			border-top-left-radius: 50rpx;
			border-top-right-radius: 50rpx;
			position: absolute;
			left: 0;
			top: 460rpx;
			.tex{
				width: 87%;
				height: 12%;
				font-weight: 600;
				margin: 0 auto;
				font-size: 38rpx;
			}


			.text {
				display: inline-block;
				color: #000;
				font-weight: 500;
			}
		}
		.choose-nickname-row {
			width: 88%;
			height: 33%;
			display: flex;
			justify-content: flex-start;
			align-items: center;
			padding: 10px 2px;
			font-size: 26rpx;
			margin: 0 auto;
			border-bottom: 1px solid #F2F2F2;
		
			.avatar-wrapper {
				width: 40px;
				height: 40px;
				margin: 0;
				padding: 0;
				margin-right: 33rpx;
		
				.avatar {
					width: 100%;
					height: 100%;
				}
			}
		}
		
		.choose-nickname-row {
			border-top: none;
		
			text {
				width: 45px;
				margin-right: 24rpx;
				color: #807E7E;
				;
			}
		}
	}
</style>
